<?php
session_start();
include_once('config/db_conn.php');
include_once('db_config/db_user.php');
include_once('db_config/db_gigs.php');
include_once('db_config/db_sentmail.php');
include_once('db_config/db_inbox.php');
include_once('db_config/db_websetting.php');
include_once('db_config/db_multiple_gigs.php');

if($_SESSION['user_id'] == '')
	reDirect('index.php');

$websetting= new websetting();
$websetting_id = '1';
$rs_websetting=$websetting->uniq_websettings('websetting_id',$websetting_id);
$data_websetting=mysql_fetch_array($rs_websetting);

$multiple_gigs =new multipleGigs();
$sentmail=new sentmail();
$inboxmail=new inbox();

$to=$_REQUEST['to'];
$gig_id=$_REQUEST['gig_id'];
$user=new user();

$rs_user=$user->uniq_user_list('user_id',$_SESSION['user_id']);
$data_user=mysql_fetch_array($rs_user);
$rs_user_tomail=$user->uniq_user_list('user_name','sandip');
$data_user_tomail=mysql_fetch_array($rs_user_tomail);
//echo $data_user_tomail['user_primary_email'];

$gigs_obj=new gigs();
$rs_gigs=$gigs_obj->uniq_gigs_list('id',$gig_id);
$data_gigs=mysql_fetch_array($rs_gigs);


$rs_sentmail = $sentmail->uniq_sentmail_list('from_id',$_SESSION['user_id']);
$rs_inbox = $inboxmail->uniq_inbox_list('from_id',$_SESSION['user_id']);


if($_REQUEST['submit'])
{

	$data_senmail=array();


		$data_senmail['gigs_id']=$gig_id;
		$data_senmail['to']=$data_user_tomail['user_primary_email'];
		$data_senmail['from']=$data_user['user_primary_email'];
		$data_senmail['sub']=$_REQUEST['subject'];
		$data_senmail['body']=$_REQUEST['body'];
		$data_senmail['attachment']=$_FILES['attachment']['name'];
		$data_senmail['date_time']=date('y-m-d h:i:s');


	$sentmail->dataInsert('ninerr_sentmail',$data_senmail);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php echo $data_websetting['change_title']; ?></title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/custom.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="javascript/jquery.min.js"></script>
<script type="text/javascript" src="javascript/jquery.simplemodal.js"></script>
<script type="text/javascript" src="javascript/init.js"></script>
<script type="text/javascript" src="javascript/init1.js"></script>
<script language="javascript" type="text/javascript" src="javascript/ajax.js"></script>
<script language="javascript" type="text/javascript">

	function read(val)
	{
		//document.getElementById("search_div").innerHTML='';
		loadFragmentInToElement('message_read_update.php?val='+val,'search_div','');


	}



</script>
<script type="text/javascript">

/*var msg_box ="You dont have permission to copy";
function dis_rightclickIE(){
	if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3))
		alert(msg_box)
}

function dis_rightclickNS(e){
	if ((document.layers||document.getElementById&&!document.all) && (e.which==2||e.which==3))
	{
	alert(msg_box)
	return false;
	}
}
if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=dis_rightclickNS;
}
else if (document.all&&!document.getElementById){
document.onmousedown=dis_rightclickIE;
}
document.oncontextmenu=new Function("alert(msg_box);return false")*/
</script>
<!-- Script by hscripts.com -->
<style type="text/css">
<!--
.style2 {color: #2791B9}
.style3 {color: #000000}
-->


</style>
<style type="text/css">

<!--

      .myNewStyle {

      font-family: Verdana, Arial, Helvetica, sans-serif;

      font-weight: bold;

      color: #000000;

      }

      -->

</style>

</head>
<body >
<div id="container" class="content">

<!--HEADER AREA-->
<?php include('header.php')?>
<!--HEADER AREA END-->
<div id="main" class="clearfix">
	<div class="main-tl">
	  	<div class="main-tr"></div>
	  	<div class="main-top"></div>
	</div>
	<div class="main-inner clearfix">
		<div class="side1">
		<!-- side1 content BEGIN =================================================================================== -->
	<h2 class="title"><span style="color: #2791B9;">Inbox /</span> All Messages</h2>
	<form method="post" id="edit_user" enctype="multipart/form-data"  action="">
		<div class="message-block clearfix">
			<div class="message-block-left">
				<p style="margin-left:40px"><a href="#">Compose a new message</a></p>
			</div>
			<div class="message-block-right">
				<div class="message-show-right-block inbox-option">
					<span class="select">Show:</span>
							<span><a title="All Messages" class="" href="messages.php?mailbox=inbox">Inbox</a>, </span>
							<span><a title="Sent Items" class="" href="messages.php?mailbox=sent">Sent Items</a> </span>
				</div>
			</div>
		</div>
		
		<table class="massage-list">
			<?php
			if($_REQUEST['mailbox']=='sent')
			{
			?>
			<tr>
              	<th colspan="2"> Subject / Gig</th>
              	<th width="24%"> To</th>
			  	<th width="18%"> Date</th>
            </tr>
			<?php

				while($data_sentmail=mysql_fetch_array($rs_sentmail))
				{
				
				$rs_user_s=$user->uniq_user_list('user_id',$data_sentmail['to_id']);
				$data_user_s=mysql_fetch_array($rs_user_s);
			?>

			<tr height="30">
				<td class="w-three" colspan="2"><a href="messages_details.php?id=<?php echo base64_encode($data_sentmail['id']);?>&type=sent"> <?php echo $data_sentmail['sub']; ?></td>
				<td class="w-two"><?php echo $data_user_s['user_name']; ?></td>
				<td class="w-four"><?php echo $data_sentmail['date_time']; ?></td>
			</tr>
            <?php

				} //end while
			} // end if
			else
			{
			?>
			<tr>
              	<th colspan="2">Subject / Gig</th>
              	<th width="24%">From</th>
			  	<th width="18%">Date</th>
            </tr>
			<?php
				while($data_inbox=mysql_fetch_array($rs_inbox))
				{
				$rs_user_i=$user->uniq_user_list('user_id',$data_inbox['to_id']);
				$data_user_i=mysql_fetch_array($rs_user_i);
			?>

			<tr height="30">
				<td colspan="2" class="w-three"
				<?php
				if($data_inbox['read_status']=='N')
				{
					echo ' style="font-weight:bold; cursor:pointer"';
				} else {
					echo ' style="cursor:pointer"';
				}
				 ?>
				>
				<a href="messages_details.php?id=<?php echo base64_encode($data_inbox['id']);?>&type=inbox"><?php echo $data_inbox['sub']; ?></a></td>
				<td class="w-two"><?php echo $data_user_i['user_name']; ?></td>
				<td class="w-four"><?php echo $data_inbox['date_time']; ?></td>
			</tr>
			<?php
				}// end while
			}// end else

			?>
        </table>
    </form>
		<!-- side1 content END =================================================================================== -->
		</div><!-- end side1 -->
		<!-- side1 END ====================== -->
		<!-- side2 BEGIN ====================== -->
		<?php include('right.php'); ?>
		<!-- side2 END ====================== -->
	</div><!-- end main-inner-->
</div><!-- end main -->

<!--FOOTER AREA-->
<?php include('footer.php');?>
 <!--FOOTER AREA END-->

</div><!-- end container -->
</body>
</html>